﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ResxCrunch.Utils;

namespace ResxCrunch
{
    /// <summary>
    /// FrmCopyDefaultValueOptions class
    /// </summary>
    public partial class FrmCopyDefaultValueOptions : Form
    {
        private CopyDefultValuesOptions copyOptions = new CopyDefultValuesOptions();

        /// <summary>
        /// Gets or sets the copy options.
        /// </summary>
        /// <value>The copy options.</value>
        public CopyDefultValuesOptions CopyOptions
        {
            get
            {
                return copyOptions;
            }

            set
            {
                copyOptions = value;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FrmCopyDefaultValueOptions"/> class.
        /// </summary>
        public FrmCopyDefaultValueOptions()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the Load event of the FrmCopyDefaultValueOptions control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void FrmCopyDefaultValueOptions_Load(object sender, EventArgs e)
        {
            this.LoadData();
            this.Enablings();
        }

        /// <summary>
        /// Loads the data into the textboxes
        /// </summary>
        private void LoadData()
        {
            if (this.CopyOptions != null)
            {
                if (this.CopyOptions.Prefix.Length > 0)
                {
                    chkPrefix.Checked = true;
                    txtPrefix.Text = this.CopyOptions.Prefix;
                }

                if (this.CopyOptions.Suffix.Length > 0)
                {
                    chkSuffix.Checked = true;
                    txtSuffix.Text = this.CopyOptions.Suffix;
                }
            }
            else
            {
                this.CopyOptions = new CopyDefultValuesOptions();
            }
        }

        /// <summary>
        /// Sets up the enabled state of controls 
        /// </summary>
        private void Enablings()
        {
            txtPrefix.Enabled = chkPrefix.Checked;
            txtSuffix.Enabled = chkSuffix.Checked;
        }

        /// <summary>
        /// Handles the CheckedChanged event of the chkPrefix control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void chkPrefix_CheckedChanged(object sender, EventArgs e)
        {
            this.Enablings();
            txtPrefix.Focus();
        }

        /// <summary>
        /// Handles the CheckedChanged event of the chkSuffix control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void chkSuffix_CheckedChanged(object sender, EventArgs e)
        {
            this.Enablings();
            txtSuffix.Focus();
        }

        /// <summary>
        /// Handles the Click event of the cmdOk control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cmdOk_Click(object sender, EventArgs e)
        {
            this.CopyOptions.Prefix = chkPrefix.Checked ? txtPrefix.Text : string.Empty;
            this.CopyOptions.Suffix = chkSuffix.Checked ? txtSuffix.Text : string.Empty;

            this.DialogResult = DialogResult.OK;

            this.Close();
        }

        /// <summary>
        /// Handles the Resize event of the FrmCopyDefaultValueOptions control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void FrmCopyDefaultValueOptions_Resize(object sender, EventArgs e)
        {

        }
    }
}
